package com.qf.service.impl;

import com.qf.entity.Address;
import com.qf.exception.BizException;
import com.qf.mapper.AddressDao;
import com.qf.service.AddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class AddressServiceImpl implements AddressService {
    @Resource
    private AddressDao addressDao;

    @Override
    public Address queryOne(int id, int state) throws BizException {
        Address address = null;
        try {
            address = addressDao.queryOne(id,state);
//            Integer.parseInt("ab");
        }catch (Exception ex) {
            ex.printStackTrace();
            throw new BizException("业务层查询异常: " + ex.getMessage());
        }
        return address;
    }

    @Override
    public List<Address> getAll(int uid, int statu) throws BizException {
        List<Address> list=new ArrayList<>();
        Address address=null;
        try {
            list =  (List<Address>) addressDao.getAll(uid,statu);
//            Integer.parseInt("ab");
        }catch (Exception ex) {
            ex.printStackTrace();
            throw new BizException("业务层查询异常: " + ex.getMessage());
        }
        return list;
    }

    @Override
    public int updateSetStatus(int uId,int aId) throws BizException {
        try {
            addressDao.updateSetStatus(uId);
            addressDao.updateSetStatusById(aId);
        }catch (Exception ex) {
            ex.printStackTrace();
            throw new BizException("业务层查询异常: " + ex.getMessage());
        }
        return 0;
    }

}

